package com.wg.other.backtrack;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * 回溯算法 - 全排列问题
 */
public class BackTrackExample {
    static List<List<Integer>> res=new LinkedList<>();

    public static void main(String[] args) {
        int[] nums=new int[]{1,2,3};
        LinkedList trackList=new LinkedList();
        backTrack_full(nums,trackList);
        res.stream().forEach((integers) -> System.out.println(integers));
    }

    /**
     * 全排列问题
     */
    public static void backTrack_full(int[] nums,LinkedList trackList){
        if(nums.length==trackList.size()){
            res.add(new LinkedList<>(trackList));
            //System.out.println(res);
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if (trackList.contains(nums[i])){
                continue;
            }
            trackList.add(nums[i]);
            backTrack_full(nums,trackList);
            trackList.removeLast();
        }
    }


}


